<?php

class Model_ServiceYesupnet extends Model_Service
{

  public function loginCheck($dpt_id, $dpt_account_login, $password="")
  {
    $service_info = $this->getServiceInfo($dpt_id);
      
    //$dbconn = $this->getServiceConn($dpt_id);
        
    //if (isset($dbconn['all']))
    if (1)
    {
      $select  = $this->db->select()->from('acc_client');
      $select->where('email = ?', $dpt_account_login);
      
      $user = $this->db->fetchRow($select);
      //Zend_Debug::dump($user);
      $passwd = md5($password);
          
      if (!$user)
      {
        $rs['status'] = false;
        $rs['message'] = 'account not found';
      }
      else
      {
          $status = $user['status'];
          $passwd_stored = $user['password'];
           
        if ($status =='Disable')
          {
              $rs['status'] = false;
                $rs['message'] = 'account not active';
          }
          elseif ($password && $passwd !=$passwd_stored)
          {
              $rs['status'] = false;
                $rs['message'] = 'wrong password';
          }
          else
          {
              $rs['status'] = true;
                $rs['dpt_account_id'] = $user['client_id'];
                $rs['dpt_account_login'] = $dpt_account_login;
                $rs['role'] = $user['role'];
                $rs['email'] = $dpt_account_login;
                
                $rs['login_area'] = 'member';
            
          }    
      }
    }
    else
    {
      $rs['status'] = false;
        $rs['message'] = 'service connection error';
    }

    return $rs; // return OK if passed
  }
  
  
  public static function addRemoteUser($client_id)
  {
	$model_service = new Model_Service();
	$service_info = $model_service->getServiceInfo(3010);  //dpt_id=3010
	
	$client_service=$model_service->getClientDptService(3010, $client_id);
	if (empty($client_service)){
		header("location: http://www.yesupnet.com/en/residential-user/");
		exit;		
	}else{
		return 0;
	}
  }

  public static function disableRemoteUser($user_id)
  {
    $config = Zend_Registry::getInstance()->get('config');
    $rpc_url = $config->paypercallapi->url;
    $client = new Zend_XmlRpc_Client($rpc_url);
    
    return $client->getProxy()->disableUser($user_id);
  }

}